<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
 <%@include file="/common/taglibs.jsp" %>
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
        <title>国际认证问卷系统</title>
        <link rel="stylesheet" href="${ctx }/css/mui.min.css"/>
     	<link rel="stylesheet" href="${ctx }/css/dw-wx-login.css"/>
   		<link rel="stylesheet" href="${ctx }/css/dw-wx-login-font.css"/>
		<script src="${ctx }/js/plugs/mui/jquery-1.8.3.min.js" type="text/javascript" ></script>
		<script src="${ctx }/js/plugs/mui/mui.min.js" type="text/javascript" ></script>
		<script>
		function refreshAutoCode(codeImgId){
			var ctx=$("#ctx").val();
			$("#"+codeImgId).attr("src",ctx+"/jcap/jcaptcha.do");
		}
		function bandUser(){
			var ctx=$("#ctx").val();
			//check一下
			var orgId = $("#orgId").val();
			if (orgId == null) {
				mui.toast('请选择机构',{ duration:'long', type:'div'});
				$('#orgId').focus();
				return false;
			}
			
			var studentId = $("#studentId").val();
			if (studentId == "") {
				mui.toast('请输入学号/工号',{ duration:'long', type:'div'});
				$('#studentId').focus();
				return false;
			}

			var vcode = $("#vcode").val();
			if (vcode == "") {
				mui.toast('请输入验证码',{ duration:'long', type:'div'});
				$('#vcode').focus();
				return false;
			}
			var url = $("#wxUserForm").attr("action");
        	$.ajax({
        		url : url,
        		type : "POST",
        		async: false,
        		data : $('#wxUserForm').serialize(),
        		success : function(data) {
        			//刷新验证码
        			refreshAutoCode("register-jcaptchaImg");
        			if(data == 0) {
        				mui.toast('验证码错误',{ duration:'long', type:'div'});
        			} else if (data == 1) {
        				mui.toast('机构编码或学号不存在',{ duration:'long', type:'div'});
        			} else {
        				window.location.href = ctx+'/wexin/mySurvey.do';
        			}
        			
        		},
        		error : function(e) {
        			//刷新验证码
        			refreshAutoCode("register-jcaptchaImg");
        			//验证码点的太快最容易导致这个问题
        			mui.toast('验证码错误',{ duration:'long', type:'div'});
        			//mui.toast('绑定失败，请联系管理员',{ duration:'long', type:'div'});
        		}
        	});
		}
		</script>

    </head>
    <body style="background: #FFFFFF;">
        <div class="header">
            <img src="${ctx }/images/dw-wx-logo.png" style="width:100%"/>
        </div>
		<div class="errmsg" id="errmsg"></div>
        <div class="login-wrap"> 
		 <form id="wxUserForm"action="${ctx }/wexin/bindAjax.do" method="post">
            <div class="login-box">
                    <div class="input-wrap">
                    <select name="orgId"  id="orgId"   style="margin-bottom:0px;color:black">
                   		<option value="" disabled selected>选择您的机构</option>
                   		<c:forEach items="${orgList }" var="en">
                   		<option value="${en.orgId }">${en.orgName }</option>
                   		</c:forEach>
                    </select>
                    <!--     <input type="text" name="orgId" placeholder="机构编码" id="orgId" value="" style="margin-bottom:0px;"/> -->
                    </div>
                    <div class="input-wrap">
                        <input type="text" name="studentId" placeholder="学号/工号" id="studentId" value="" style="margin-bottom:0px;"/>
                    </div>
                    <div class="input-wrap">
                        <input type="text" name="vcode" placeholder="验证码" id="vcode" style="margin-bottom:0px;"/>
                       <img id="register-jcaptchaImg" onclick="refreshAutoCode('register-jcaptchaImg')" src="${ctx }/jcap/jcaptcha.do" alt="验证码" class="validate-code">
                    </div>
                 <input type="hidden" name="ctx" id="ctx" value="${ctx }"/>
            </div>
			<div class="choose_box">
<!-- 			<input type="checkbox" checked="checked" name="rember" id="rember"  value="1" style="-webkit-appearance:checkbox;"/>记住密码 -->
			</div>
		</form>
			<div class="btns"></div>
            <a href="javascript:void(0)" class="weui_btn login-btn weui_btn_primary" onclick="bandUser()">绑定微信</a> 

        </div>
        <div class="footer">
            Powered by ACBSP China
        </div>
    </body>
</html>
